<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作业20</title>
    <script>
        /*
        用户输入一个数字n，计算1+2+3+4+……n的和。
        */
        var num = prompt("请输入一个数字:");
        var sum = 0;

        for(var i=1; i<=num; i++){
            sum +=i;
        }

        alert("从1累加到"+num+",结果是"+sum);
    </script>
</head>
<body>
    
</body>
</html>